package com.bluegalaxy.sitescore.service.impl;

import com.bluegalaxy.sitescore.entity.Soil;
import com.bluegalaxy.sitescore.entity.TbSoilExposure;
import com.bluegalaxy.sitescore.service.SoilService;
import org.springframework.stereotype.Service;

import java.math.BigDecimal;
import java.math.BigInteger;
import java.math.RoundingMode;

/**
 * Created by LZRuil on 2017/11/26.
 */
@Service
public class SoilServiceImpl  implements SoilService {

    @Override
    public int CaculateLR(int attractAccess,int areasOfContamination) {
        //通过区域及面积查附近人口LR
        if(attractAccess == 0){
            return 0;
        }else if(attractAccess==5){
            if (areasOfContamination<=60){
                return 5;
            }else if(areasOfContamination==80){
                return 25;
            }else if(areasOfContamination==100){
                return 125;
            }
        }else if(attractAccess==10){
            if(areasOfContamination<=40){
                return 5;
            }else if (areasOfContamination==60){
                return 25;
            }else if (areasOfContamination==80){
                return 50;
            }else if (areasOfContamination==100){
                return 125;
            }
        }else  if (attractAccess==25){
            if (areasOfContamination<=20){
                return 5;
            }else if (areasOfContamination==40) {
                return 25;
            }else if (areasOfContamination==60){
                return 50;
            }else if (areasOfContamination==80){
                return 125;
            }else if (areasOfContamination==100){
                return 250;
            }
        }else if (attractAccess==50){
            if(areasOfContamination==5){
                return 5;
            }else if (areasOfContamination<=20){
                return 25;
            }else if (areasOfContamination==40) {
                return 50;
            }else if (areasOfContamination==60){
                return 125;
            }else if (areasOfContamination==80){
                return 250;
            }else if (areasOfContamination==100){
                return 375;
            }
        }else if (attractAccess==75){
            if(areasOfContamination==5){
                return 25;
            }else if (areasOfContamination<=20){
                return 50;
            }else if (areasOfContamination==40) {
                return 125;
            }else if (areasOfContamination==60){
                return 250;
            }else if (areasOfContamination==80){
                return 375;
            }else if (areasOfContamination==100){
                return 500;
            }
        }else if (attractAccess==100){
            if(areasOfContamination==5){
                return 50;
            }else if (areasOfContamination<=20){
                return 125;
            }else if (areasOfContamination==40) {
                return 250;
            }else if (areasOfContamination==60){
                return 375;
            }else if (areasOfContamination==80){
                return 500;
            }else if (areasOfContamination==100){
                return 500;
            }
        }
        return 0;
    }

    @Override
    public int CaculateWC(int hazaQuantityData, BigDecimal toxicity) {

       /* double characteristicProduct = hazaQuantityData * toxicity;
        if(characteristicProduct==0){
            return 0;
        }else if(characteristicProduct)*/
        return 0;
    }

    @Override
    public int CaculateT(int residentIndividual, int pop1, int pop2,
                         int worker,int resources,int terrestrialSensEnvion) {
        //计算人口T
        int pop = pop1*10+pop2;

        return residentIndividual+pop+worker+resources+terrestrialSensEnvion;
    }

    @Override
    public BigDecimal CaculateScore(BigDecimal resident, BigDecimal nearby) {
        BigDecimal score = null;
        score = resident.add(nearby).divide(new BigDecimal("82500"),2, RoundingMode.HALF_UP);
        return score;
    }

    @Override
    public BigDecimal CaculateResident(int exposureInt, int wcInt, BigDecimal targets) {
        BigDecimal exposure = new BigDecimal(exposureInt);
        BigDecimal wc = new BigDecimal(wcInt);
        return exposure.multiply(wc).multiply(targets);
    }

    @Override
    public BigDecimal CaculateNearby(int lrInt, int wcInt, BigDecimal targets) {
        BigDecimal lr = new BigDecimal(lrInt);
        BigDecimal wc = new BigDecimal(wcInt);
        return lr.multiply(wc).multiply(targets);
    }

    @Override
    public boolean judgeData(TbSoilExposure soil) {
        if (soil.getLikelihood_of_exposure() != 550 && soil.getLikelihood_of_exposure() != 0) {
            return false;
        }
        if (soil.getResident_individual() != 0 && soil.getResident_individual() != 45 && soil.getResident_individual() != 50) {
            return false;
        }
        if (soil.getPop_concent1() < 0) {
            return false;
        }
        if (soil.getPop_concent2() < 0) {
            return false;
        }
        if (soil.getWorker() != 0 && soil.getWorker() != 5 && soil.getWorker() != 10 && soil.getWorker() != 15) {
            return false;
        }
        if (soil.getResources() != 0 && soil.getResources() != 5) {
            return false;
        }
        if (soil.getTerrestrial_sens_envion() != 0 && soil.getTerrestrial_sens_envion() != 25 && soil.getTerrestrial_sens_envion() != 50 && soil.getTerrestrial_sens_envion() != 75 && soil.getTerrestrial_sens_envion() != 100) {
            return false;
        }
        if (soil.getAttract_access() != 0 && soil.getAttract_access() != 5 && soil.getAttract_access() != 10 && soil.getAttract_access() != 25 && soil.getAttract_access() != 50 && soil.getAttract_access() != 75 && soil.getAttract_access() != 100) {
            return false;
        }
        if (soil.getAreas_of_contamination() != 5 && soil.getAreas_of_contamination() != 20 && soil.getAreas_of_contamination() != 40 && soil.getAreas_of_contamination() != 60 && soil.getAreas_of_contamination() != 80 && soil.getAreas_of_contamination() != 100) {
            return false;
        }
        if (soil.getNearby_individual() != 0 && soil.getNearby_individual() != 1) {
            return false;
        }
        if (soil.getPop_with() < 0) {
            return false;
        }
        return true;
    }
}
